@extends('layouts.app')


@section('title', '管理员列表')


@section('content')
	<input type="hidden" id="_token" name="_token" value="{{ csrf_token() }}">
	<fieldset class="layui-elem-field layui-field-title">
	  <legend>管理员列表</legend>
	</fieldset>

	<div class="layui-form">
		<button id="add" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe608;</i>新增</button>
	</div>
	
	<div class="layui-form">
	  	<table class="layui-table">
		    <colgroup>
		    	<col width="50">
			    <col width="150">
			    <col width="150">
			    <col width="100">
			    <col width="100">
			    <col>
			    <col width="100">
		    </colgroup>
		    <thead>
		      	<tr>
		      		<th>ID</th>
			        <th>名称</th>
			        <th>账号</th>
			        <th>性别</th>
			        <th>状态</th>
			        <th>头像</th>
			        <th>操作</th>
		      	</tr> 
		    </thead>
		    <tbody id="app" v-cloak>
			    <tr v-for="admin in list">
			    	<td>@{{ admin.id }}</td>
			        <td>@{{ admin.name }}</td>
			        <td>@{{ admin.account }}</td>
			        <td>@{{ admin.sex == 1 ? '男' : '女' }}</td>
			        <td>@{{ admin.status == 1 ? '启用' : '关闭' }}</td>
			        <td>@{{ admin.head_img }}</td>
			        <td>
			        	<div class="layui-btn-group">
						    <!-- <button type="button" class="layui-btn layui-btn-primary layui-btn-xs"><i class="layui-icon"></i></button> -->
						    <button type="button" class="layui-btn layui-btn-primary layui-btn-xs update" v-bind:onclick="'edit('+admin.id+')'"><i class="layui-icon"></i></button>
						    <button type="button" class="layui-btn layui-btn-primary layui-btn-xs" v-bind:onclick="'deleteAdmin('+admin.id+',\''+admin.name+'\')'"><i class="layui-icon"></i></button>
						</div>
			        </td>
			    </tr>
		    </tbody>
	  	</table>
	  	<div id="demo1"></div>

	</div>

@endsection

@section('script')
	<script src="{{ URL::asset('/') }}skin/lib/vue.js"></script>
	<script type="text/javascript">

		var app = new Vue({
			el : '#app',
			data : {
				list : {!! $list !!}
			}
		})

		layui.use(['laypage', 'layer'], function() {
			var laypage = layui.laypage, layer = layui.layer;
			//总页数大于页码总数
			laypage.render({
			    elem: 'demo1'
			    ,count: {{ $count }} //数据总数
			    // ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
			    ,jump: function(obj, first){
			        var page = obj.curr, size = obj.limit, _token = $('#_token').val();
			        if (!first) {
			        	var data = {page : page, size : size, _token : _token}
			        	$.post("{{ url('admin/adminUser/get_list') }}", data, function(result) {
			        		if (result.code == 1) {
			        			app._data.list = result.data.list;
			        		}
			        	})
			        }
			    }
			});
		})

		/**
	    * 删除管理员
	    */
	    function deleteAdmin(id, name)
	    {
	    	var _token = $('#_token').val()
	        layer.msg(
	            '确定删除管理员--'+name,
	            {
	                icon: 3,
	                time: 10000,
	                btn: ['确认', '取消'],
	                yes: function() {
	                    $.ajax({
	                    	url:'{{ url("admin/adminUser/delete")}}/'+id, 
	                    	method: 'DELETE',
	                    	data:{_token: _token},
	                    	success: function(result){
		                        if (result.code == 0) {
		                            layer.msg(result.msg, {icon: 1, time: 2000}, function(){
		                                window.location.reload()
		                            })
		                        } else {
		                            layer.msg(result.msg, {icon: 2, time: 2000})
		                        }
		                    }
	                    })
	                }
	            }
	        )
	    }    

		$('#add').click(function() {
			layer.open({
		        type: 2 //此处以iframe举例
		        ,title: '新增管理员'
		        //,maxmin: true
		        ,area: ['600px', '600px']
		        ,shade: 0.2
		        ,content: '{{ url("admin/adminUser/edit") }}'	        
		    });
		})
		function edit(id){
			layer.open({
		        type: 2 //此处以iframe举例
		        ,title: '编辑管理员'
		        //,maxmin: true
		        ,area: ['600px', '600px']
		        ,shade: 0.2
		        ,content: '{{ url("admin/adminUser/edit") }}/'+id        
		    });
		}
	</script>

@endsection
